//
//  NewHomeBannerCell.m
//  GC_OC
//
//  Created by  Quan He on 2022/4/9.
//

#import "NewHomeBannerCell.h"
#import "DCCycleScrollViewCell.h"
#import <SDCycleScrollView/SDCycleScrollView.h>
#import <SDWebImage/SDWebImage.h>
#import <AVFoundation/AVFoundation.h>
@interface NewHomeBannerCell()<SDCycleScrollViewDelegate>
@property (nonatomic, strong) SDCycleScrollView* cycleScrollView;
@property (nonatomic, strong) AVPlayer * player;
@end

@implementation NewHomeBannerCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _dataArr = [NSMutableArray array];
        self.contentView.backgroundColor = [UIColor colorWithRed:0.96 green:0.97 blue:0.98 alpha:1.00];
        self.backgroundColor = [UIColor colorWithRed:0.96 green:0.97 blue:0.98 alpha:1.00];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self addSubview:self.cycleScrollView];
    }
    return self;
}


- (void)setDataArr:(NSMutableArray<HomeBannerModel *> *)dataArr {
    _dataArr = dataArr;

    NSMutableArray *imageArr = [NSMutableArray array];
    NSMutableArray *titleArr = [NSMutableArray array];
    BOOL haveMedia = NO;
    for (HomeBannerModel *model in dataArr) {
        [imageArr addObject:model.cover_image];
        [titleArr addObject:model.rotation_name];
        if (model.media_file.length > 0) {
            haveMedia = YES;
        }
    }
    
    self.cycleScrollView.autoScroll = false;
    self.cycleScrollView.imageURLStringsGroup = imageArr;
}

/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
//    HomeBannerModel *model = self.dataArr[index];
//    NSURL *URL = [NSURL URLWithString:model.link];
//    [[UIApplication sharedApplication] openURL:URL options:nil completionHandler:nil];
}

/** 图片滚动回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index {

}
//// 不需要自定义轮播cell的请忽略以下两个的代理方法
//
//// ========== 轮播自定义cell ==========
//
///** 如果你需要自定义cell样式，请在实现此代理方法返回你的自定义cell的class。 */
- (Class)customCollectionViewCellClassForCycleScrollView:(SDCycleScrollView *)view{
    return [DCCycleScrollViewCell class];
}



/** 如果你自定义了cell样式，请在实现此代理方法为你的cell填充数据以及其它一系列设置 */
- (void)setupCustomCell:(UICollectionViewCell *)cell forIndex:(NSInteger)index cycleScrollView:(SDCycleScrollView *)view{
    DCCycleScrollViewCell *customCell = (DCCycleScrollViewCell *)cell ;
    customCell.model = self.dataArr[index % self.dataArr.count];
}

- (SDCycleScrollView *)cycleScrollView{
    if (_cycleScrollView == nil) {
        _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(5, 10, SCREEN_WIDTH - 10, 140) delegate:self placeholderImage:nil];
        _cycleScrollView.clipsToBounds = YES;
        _cycleScrollView.layer.cornerRadius = 6;
        _cycleScrollView.autoScroll = YES;
        _cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
//        _cycleScrollView.imgCornerRadius = 10;
//        _cycleScrollView.itemWidth =SCREEN_WIDTH-wid(50);
//        _cycleScrollView.itemSpace=wid(10);
    }
    return _cycleScrollView;
}

@end
